<?php
include("./config.php");
include("./utils.php");
//checkLogin();
?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>编辑</title>
  <?php include 'scripts-inc.php' ?>

  <script>
  var gData={};
  var appid = '<?php echo $_GET["appid"]; ?>';
  var id = '<?php echo $_GET["id"]; ?>';
  var gUserID = '<?php echo $_GET["id"]; ?>';
  var gID = id;
  var gAppID = appid;
  var gLang = "<?php echo getFromMap($_GET, 'lang', 'cn'); ?>";


  var get_data = function(appid, shortcutid, lang, op){
    var u = 'query.php?op='+op+'&id='+shortcutid+'&appid='+appid;
    if(lang) u = u + '&lang='+lang;
    $.ajax({url:u,
      dataType:"json",
      async:true,
      success : function(msg, textStatus) {
        var data = msg[0];
        if(data){
          gID = data["shortcutid"];
          id = gID;
          $("#tid").val(gID);
          $("#tshortcut").val(data["shortcut"]);
          $("#tskin").val(data["skin"]);
          $("#tdes").val(data["des"]);
          $("#tname").val(data["name"]);
          $("#tcontext").val(data["context"]);
          $("#tdes_en").val(data["des_en"]);
          $("#tname_en").val(data["name_en"]);
          $("#tcontext_en").val(data["context_en"]);
          $(document).attr("title",'编辑[' + data['shortcut']+data['name']+']');//修改title值
          var appid = data['appid'];
          var shortcutid = data['shortcutid'];
          $("#goback").attr("href","./show.php?appid="+gAppID+"&id="+gID);
          $("#goback-app").attr("href","./show-app.php?appid="+gAppID);
          gData = data;
        }
      }
    },"text");
  }
  $(function(){
    get_data(appid, id, gLang, 'one-shortcut');

    function updateOp(op, v){
      var data = {
        id:gID,
        appid:appid,
        op:op,
        value:v
      };

      show_msg("#content", "提交中...");
      $.post("update-data.php", data, function(msg){
        show_msg("#content", "修改完成");
      });
    }

    $("#save-shortcut").click(function(){
      updateOp("save-shortcut", $("#tshortcut").val());
    });
    $("#save-name").click(function(){
      updateOp("save-name", $("#tname").val());
    });
    $("#save-des").click(function(){
      updateOp("save-des", $("#tdes").val());
    });
    $("#save-context").click(function(){
      updateOp("save-context", $("#tcontext").val());
    });

    // English
    $("#save-name-en").click(function(){
      updateOp("save-name-en", $("#tname_en").val());
    });
    $("#save-des-en").click(function(){
      updateOp("save-des-en", $("#tdes_en").val());
    });
    $("#save-context-en").click(function(){
      updateOp("save-context-en", $("#tcontext_en").val());
    });

    $("#save-skin").click(function(){
      updateOp("save-skin", $("#tskin").val());
    });



    $("#next-shortcut").click(function(){
      get_data(gAppID, gID, gLang, 'next-shortcut');
    });
    $("#prev-shortcut").click(function(){
      get_data(gAppID, gID, gLang, 'prev-shortcut');
    });


    $("#del-shortcut").click(function(){
      var data = {
        appid:appid,
        id:id,
        op:'del-shortcut'
      };

      $("#content").text("提交中...");
      $.post("update-data.php", data, function(msg){
        show_msg("#content", "已经删除");
        $("#back").text("返回首页");
        $("#del-shortcut").hide();
      });
    });
  });//end of $(function(){

  </script>
</head>
<body>
<!-- template -->
<!-- end of template -->


<div id="wrapper">
<div id="container">
<!-- .................................................... -->

<div id="nav_data_src">
    <?php include 'navbars-inc.php' ?>
</div>

<div id="tcontainer" class="center">
<div class="container-fluid">
    <div class="form-group row">
      <label for="tid" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">ID</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tid" name="tid" placeholder="" disabled/>
      </div>
      <a href="javascript:window.opener=null;window.open('','_self');window.close();"
       class="lang-close btn btn-danger col-xs-2 col-sm-1 col-md-1 col-lg-1 text-center" 
       id="" >关闭</a>
    </div>

    <div class="form-group row">
      <label for="tshortcut" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">快捷键</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tshortcut" name="tshortcut" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-shortcut">保存</button>
    </div>

    <div class="form-group row">
      <label for="tname" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">功能</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tname" name="tname" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-name">保存</button>
    </div>
    <div class="form-group row">
      <label for="tcontext" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">上下文</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tcontext" name="tcontext" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-context">保存</button>
    </div>
    <div class="form-group row">
      <label for="tdes" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">说明</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <textarea class="form-control" id="tdes" rows="3" name="tdes" placeholder=""></textarea>
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-des">保存</button>
    </div>

    <!-- English -->
    <div class="form-group row">
      <label for="tname_en" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">Function</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tname_en" name="tname_en" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-name-en">Save</button>
    </div>
    <div class="form-group row">
      <label for="tcontext_en" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">Context</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tcontext_en" name="tcontext_en" placeholder="">
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-context-en">Save</button>
    </div>
    <div class="form-group row">
      <label for="tdes_en" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">Description</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <textarea class="form-control" id="tdes_en" rows="3" name="tdes_en" placeholder=""></textarea>
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-des-en">Save</button>
    </div>

    <div class="form-group row">
      <label for="tskin" class="col-xs-3 col-sm-1 col-md-1 col-lg-1 control-label">皮肤</label>
      <div class="col-xs-7 col-sm-6 col-md-6 col-lg-6">
        <input type="" class="form-control" id="tskin" name="tskin" placeholder="">
        <a class="btn btn-lg list-group-item-default" onclick="$('#tskin').val(0)">0</a>
        <a class="btn btn-lg list-group-item-danger" onclick="$('#tskin').val(1)">1</a>
        <a class="btn btn-lg list-group-item-info" onclick="$('#tskin').val(2)">2</a>
        <a class="btn btn-lg list-group-item-warning" onclick="$('#tskin').val(3)">3</a>
        <a class="btn btn-lg list-group-item-success" onclick="$('#tskin').val(4)">4</a>
        <a class="btn btn-lg list-group-item-primary" onclick="$('#tskin').val(5)">5</a>
      </div>
      <button type="submit" class="btn btn-primary col-xs-2 col-sm-1 col-md-1 col-lg-1" id="save-skin">保存</button>
    </div>

  <div class="clearfix"></div>
  <div class="form-group row">
      <button id="prev-shortcut" href="#" class="btn btn-lg btn-default col-xs-2 col-sm-1 col-md-1 col-lg-1 text-center" >&lt;&lt;</button>
      <a href="./index.php" class="lang-return-keyboard btn btn-lg btn-default col-xs-4 col-sm-2 col-md-2 col-lg-2 text-center" id="goback" >返回键盘</a>
      <a href="./index.php" class="btn btn-lg btn-warning col-xs-4 col-sm-2 col-md-2 col-lg-2 text-center" id="goback-app" >返回列表</a>
      <button id="next-shortcut" href="#" class="btn btn-lg btn-success col-xs-2 col-sm-2 col-md-2 col-lg-2 text-center" >&gt;&gt;</button>
  </div>
<div class="form-group row">
    <div class="col-xs-8 col-sm-3 col-md-3 col-lg-3 text-center">
      <div id="content"></div>
    </div>
</div>
</div>


</div> <!-- end of tcontainer -->

<!-- .................................................... -->
</div><!-- end of container -->
</div><!-- end of wrapper -->
</body>
</html>
